import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const modules: any = import.meta.globEager("./modules/**/*.ts");

const routes: Array<RouteRecordRaw> = [];
for (const key in modules) {
  routes.push(...modules[key].default);
}

const router = createRouter({
  history: createWebHashHistory(), // history 模式则使用 createWebHistory()
  routes,
});

router.beforeEach(async (_to, _from, next) => {
  const title: string = _to.meta.title || "";
  document.title = title;
  NProgress.start();
  next();
});

router.afterEach((_to) => {
  NProgress.done();
});

export default router;
